# -*- encoding:utf-8 -*-
# @time: 2023/3/19 12:15
# @author: Maxs_hu
from django.template import Library
from django.conf import settings
from copy import deepcopy

register = Library()


@register.inclusion_tag('tag/menu.html')
def my_template(request):
    user_list = deepcopy(settings.NB_MENU.get(request.user_obj.role))  # 拷贝一份原版

    for item in user_list:
        item['class'] = 'hide'  # 默认为hide
        for row in item['children']:
            # if request.path_info == row['url']:  # v1
            if request.user_obj.parent == row['name']:  # v2
                row['class'] = 'active'  # 添加active样式
                item['class'] = ''  # 当前不隐藏

    return {'user_list': user_list}


